from bs4 import BeautifulSoup

# 打开本地网页文件
# with open('index.html', 'r') as f:
with open('index.html', 'r') as f:
    html_doc = f.read()

# 创建BeautifulSoup对象，指定解析器为"html.parser"
soup = BeautifulSoup(html_doc, 'html.parser')

# 提取网页标题
title = soup.title.string
print("标题:", title)

# 提取所有的段落（p标签）
paragraphs = soup.find_all('p')
for paragraph in paragraphs:
    print("段落:", paragraph.text)

# 提取所有的链接（a标签）
links = soup.find_all('a')
for link in links:
    print("链接:", link.get('href'))
